#ifndef __NT35510_H
#define __NT35510_H

#include "stm32f10x.h"
#include "main.h"

#define SETXCMD 0x2A00
#define SETYCMD 0x2B00
#define WRAMCMD 0x2C00

enum DIR{
	VDIR=0,
	HDIR,
};

typedef struct
{
	uint8_t dir;
	uint16_t width;
	uint16_t height;
	uint32_t id;
}NT35510_Info;

//LCD的画笔颜色和背景色
extern uint16_t POINT_COLOR; //默认红色
extern uint16_t BACK_COLOR;	 //背景颜色.默认为白色
extern NT35510_Info info;
//////////////////////////////////////////////////////////////////////////////////
//-----------------LCD端口定义----------------
#define	NT35510_LED PBout(0) 		//LCD背光  PB0
//LCD地址结构体
typedef struct
{
	volatile uint16_t NT35510_REG;
	volatile uint16_t NT35510_RAM;
} NT35510_TypeDef;
//使用NOR/SRAM的 Bank1.sector4,地址位HADDR[27,26]=11 A10作为数据命令区分线
//注意设置时STM32内部会右移一位对其!
#define NT35510_BASE ((uint32_t)(0x6C000000 | 0x000007FE))
#define NT35510 ((NT35510_TypeDef *)NT35510_BASE)
//////////////////////////////////////////////////////////////////////////////////

//扫描方向定义
#define L2R_U2D 0 //从左到右,从上到下
#define L2R_D2U 1 //从左到右,从下到上
#define R2L_U2D 2 //从右到左,从上到下
#define R2L_D2U 3 //从右到左,从下到上

#define U2D_L2R 4 //从上到下,从左到右
#define U2D_R2L 5 //从上到下,从右到左
#define D2U_L2R 6 //从下到上,从左到右
#define D2U_R2L 7 //从下到上,从右到左

#define DFT_SCAN_DIR L2R_U2D //默认的扫描方向

//画笔颜色
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430	 //灰色
//GUI颜色
#define DARKBLUE 0X01CF	 //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458	 //灰蓝色
//以上三色为PANEL的颜色

#define LIGHTGREEN 0X841F //浅绿色
//#define LIGHTGRAY        0XEF5B //浅灰色(PANNEL)
#define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色

#define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12		 //浅棕蓝色(选择条目的反色)

void NT35510_Initialization(void);																																					//初始化
void NT35510_DisplayOn(void);																																								//开显示
void NT35510_DisplayOff(void);																																							//关显示
void NT35510_Clear(uint16_t Color);																																					//清屏
void NT35510_SetCursor(uint16_t Xpos, uint16_t Ypos);																												//设置光标
void NT35510_DrawPoint(uint16_t x, uint16_t y);																															//画点
void NT35510_Fast_DrawPoint(uint16_t x, uint16_t y, uint16_t color);																				//快速画点
uint16_t NT35510_ReadPoint(uint16_t x, uint16_t y);																													//读点
void NT35510_Draw_Circle(uint16_t x0, uint16_t y0, uint8_t r);																							//画圆
void NT35510_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);																	//画线
void NT35510_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);															//画矩形
void NT35510_Fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color);											//填充单色
void NT35510_Color_Fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t *color);								//填充指定颜色
void NT35510_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint8_t size, uint8_t mode);											//显示一个字符
void NT35510_ShowNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size);											//显示一个数字
void NT35510_ShowxNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size, uint8_t mode);				//显示 数字
void NT35510_ShowString(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t size, uint8_t *p); //显示一个字符串,12/16字体

void NT35510_WriteReg(uint16_t NT35510_Reg, uint16_t NT35510_RegValue);
uint16_t NT35510_ReadReg(uint16_t NT35510_Reg);
void NT35510_WriteRAM_Prepare(void);
void NT35510_WriteRAM(uint16_t RGB_Code);
void NT35510_SSD_BackLightSet(uint8_t pwm);																					//SSD1963 背光控制
void NT35510_Scan_Dir(uint8_t dir);																									//设置屏扫描方向
void NT35510_Display_Dir(uint8_t dir);																							//设置屏幕显示方向
void NT35510_Set_Window(uint16_t sx, uint16_t sy, uint16_t width, uint16_t height); //设置窗口
uint32_t NT35510_CheckID(void);
//LCD分辨率设置
#define SSD_HOR_RESOLUTION 800 //LCD水平分辨率
#define SSD_VER_RESOLUTION 480 //LCD垂直分辨率
//LCD驱动参数设置
#define SSD_HOR_PULSE_WIDTH 1		//水平脉宽
#define SSD_HOR_BACK_PORCH 46		//水平前廊
#define SSD_HOR_FRONT_PORCH 210 //水平后廊

#define SSD_VER_PULSE_WIDTH 1	 //垂直脉宽
#define SSD_VER_BACK_PORCH 23	 //垂直前廊
#define SSD_VER_FRONT_PORCH 22 //垂直前廊
//如下几个参数，自动计算
#define SSD_HT (SSD_HOR_RESOLUTION + SSD_HOR_BACK_PORCH + SSD_HOR_FRONT_PORCH)
#define SSD_HPS (SSD_HOR_BACK_PORCH)
#define SSD_VT (SSD_VER_RESOLUTION + SSD_VER_BACK_PORCH + SSD_VER_FRONT_PORCH)
#define SSD_VPS (SSD_VER_BACK_PORCH)

#endif /* __NT35510_H */